#include<bits/stdc++.h>
using namespace std;
#define pc putchar
#define pb push_back
#define mp make_pair
#define ls (id<<1)
#define rs ((id<<1)|1)
#define mid ((l+r)>>1)
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
char buf[(1<<21)+5],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

int read(){
    int ret=0,f=0; char ch=gc();
    while(ch<'0'||ch>'9') f|=(ch=='-'),ch=gc();
    while(ch>='0'&&ch<='9') ret=(ret<<1)+(ret<<3)+(ch^48),ch=gc();
    return f?-ret:ret;
}

void write(int x){
    if(!x) return pc('0'),void();
    if(x<0) pc('-'),x=-x;
    int stk[30],tp=0;
    while(x) stk[++tp]=x%10,x/=10;
    while(tp) pc('0'+stk[tp--]);
    return;
}

const int Maxn=1e6+10;
int N,Ls[Maxn],Rs[Maxn],Fa[Maxn],dep[Maxn],Ans[Maxn];
int L[Maxn],R[Maxn],F[Maxn],rt;
bool f1,f2;

void DFS(int x,int t){
    if(!x) return;
    if(x!=t) dep[x]=dep[F[x]]+1;
    DFS(L[x],t),DFS(R[x],t);
}

// void Solve1(){
//     dep[1]=0; DFS(1,1);
//     For(i,1,N){
//         if(dep[i]) Ans[i]=(1+dep[i])*dep[i]/2;
//         if(dep[i]!=N) Ans[i]+=(N-dep[i])*(N-dep[i]-1)/2;
//     }
//     For(i,1,N) write(Ans[i]),pc('\n');
// }

bool check(int x){ return x==R[F[x]]; }

void Rotate(int x){
    int p=F[x];
    if(!check(x)){
        L[p]=R[x],F[R[x]]=p;
        bool f=check(p);
        F[x]=F[p]; if(!f) L[F[p]]=x; else R[F[p]]=x;
        R[x]=p,F[p]=x;
        if(p==rt) rt=x;
    }else{
        R[p]=L[x],F[L[x]]=p;
        bool f=check(p);
        F[x]=F[p]; if(!f) L[F[p]]=x; else R[F[p]]=x;
        L[x]=p,F[p]=x;
        if(p==rt) rt=x;
    }
}

void Solve(int x){
    rt=1; 
    while(F[x]){
        if(F[x]==rt) Rotate(x);
        else if(check(x)==check(F[x])) Rotate(F[x]),Rotate(x);
        else Rotate(x),Rotate(x);
    }
    dep[x]=0; DFS(x,x); For(i,1,N) Ans[i]+=dep[i];
}

int main(){
    freopen("dream.in","r",stdin);
    freopen("dream.out","w",stdout);
    N=read();
    For(i,1,N){
        Ls[i]=read(),Rs[i]=read(),Fa[Ls[i]]=Fa[Rs[i]]=i;
        if(Rs[i]) f2=1;
    }
    // if(!f2) Solve1(),exit(0);
    For(i,1,N){
        For(j,1,N) L[j]=Ls[j],R[j]=Rs[j],F[j]=Fa[j];
        Solve(i);
    }
    For(i,1,N) write(Ans[i]),pc('\n');
    return 0;
}